﻿/*
Copyright (c) 2010 Vratislav Cermak (vratacermak@gmail.com)
 
This file is part of TeachMe Project. See http://code.google.com/p/teach-me for more information.
 
TeachMe is an open source project. Using of TeachMe is free of charge.
It is distributed under GNU General Public License version 3 (GPLv3).
GPLv3 can be found at http://www.gnu.org/licenses/gpl.html.
 
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE.  See the license for more details.
*/

namespace TeachMe.Application.Forms.Options
{
    using System.Windows.Forms;

    using TeachMe.Application.Properties;

    public partial class Intervals : OptionsControl
    {
        private ErrorProvider _provider;

        public Intervals()
        {
            _provider = new ErrorProvider(this);

            InitializeComponent();
        }

        internal override void LoadOptions()
        {
            tbNewEntryInterval.Value = UserSettings.NewEntryInterval.Value;
            tbNewEntryIntervalInTurboMode.Value = UserSettings.TurboModeInterval.Value;
            tbHintInterval.Value = UserSettings.HintInterval.Value;
            tbHotkeySuspendInterval.Value = UserSettings.HotkeySuspendInterval.Value;

            CheckIntervals();
        }

        internal override void SaveOptions()
        {
            UserSettings.NewEntryInterval.Value = tbNewEntryInterval.Value;
            UserSettings.TurboModeInterval.Value = tbNewEntryIntervalInTurboMode.Value;
            UserSettings.HintInterval.Value = tbHintInterval.Value;
            UserSettings.HotkeySuspendInterval.Value = tbHotkeySuspendInterval.Value;
        }

        private void CheckIntervals()
        {
            if (tbNewEntryInterval.Value * 60 < tbHintInterval.Value)
            {
                _provider.SetError(txHintIntervalValue, Resources.HintIntervalTooHigh);
            }
            else
            {
                _provider.Clear();
            }
        }

        private void OnIntervalChanged(object sender, System.EventArgs e)
        {
            CheckIntervals();
        }
    }
}
